<!--
 * <p>@author 陈子睿</p>
 * <p>@Date: 2021/3/23</p>
 * <p>@Time: 15:16</p>
 * <p>@Description: 我的运单</p>
-->

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>我的运单</title>

    <link rel="stylesheet" href="../layui/css/layui.css" media="all">
    <script src="../js/jquery-3.1.1.min.js"></script>
    <script src="../layui/layui.js"></script>
    <script src="../js/tools.js"></script>
    <style>
        body {
            margin: 10px;
        }

        .demo-carousel {
            height: 200px;
            line-height: 200px;
            text-align: center;
        }
    </style>
</head>
<body>
<div>
    <form action="">
        <div class="list_main">
            <div class="list_query">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label"></label>
                        <div class="layui-input-inline">
                            <input type="tel" name="staffName" lay-verify="required" autocomplete="off"
                                   class="layui-input"
                                   value="" id="staffName" placeholder="请输入关键字">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label"></label>
                        <div class="layui-input-inline">
                            <input type="text" name="goDate" id="goDate" autocomplete="off" class="layui-input"
                                   readonly placeholder="请输入开始日期">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label"></label>
                        <div class="layui-input-inline">
                            <input type="text" name="outDate" id="outDate" autocomplete="off" class="layui-input"
                                   readonly placeholder="请输入结束日期">
                        </div>
                    </div>
                    <input type="button" class="layui-btn layui-btn-sm" id="souSuo" name="souSuo" value="查找"></input>
                </div>
            </div>
        </div>
    </form>
    <table class="layui-hide" id="demo" lay-filter="test"></table>
</div>

<!--  这是编辑框里面的  -->
<script type="text/html" id="barDemo">
    <button type="button" class="layui-btn layui-btn-xs layui-btn-radius" lay-event="edit">确认送达</button>
    <!--    <button type="button" class="layui-btn layui-btn-xs layui-btn-disabled">已送达</button>-->
</script>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <!--        <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" lay-event="add"><i-->
        <!--                class="layui-icon"></i></button>-->
        <!--        <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" lay-event="delete"><i class="layui-icon"></i>-->
        <!--        </button>-->
    </div>
    </div>
    </div>
</script>

<script>
    var table;
    layui.config({
        version: '1606406696877' //为了更新 js 缓存，可忽略
    });

    //如果要选日期就要加  ‘laydate’,以及。。。（一下带有注释的）
    layui.use(['layer', 'table', 'jquery', 'laydate'], function () {    //日期
        var layer = layui.layer //弹层
            , $ = layui.$//使用内置jquery
            , laydate = layui.laydate

        //日期
        laydate.render({
            elem: '#goDate'
        });

        //日期
        laydate.render({
            elem: '#outDate'
        });

        table = layui.table //表格

        //执行一个 table 实例 渲染
        table.render({
            elem: '#demo'
            , id: 'testReload'
            , height: 555
            , url: '/logisticsCarriage/queryAll2' //数据接口
            , title: '我的运单'
            , page: true //开启分页
            , toolbar: '#toolbarDemo' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            // , totalRow: true //开启合计行
            , cols: [[ //表头
                {type: 'checkbox', fixed: 'left', width: 50}
                , {field: 'batchNum', title: '批次号', width: 170}
                , {field: 'mapName', title: '出发地', width: 130}
                , {field: 'mapName2', title: '目的地', width: 210}
                , {field: 'carriageStarttime', title: '出发时间', width: 140}
                , {field: 'carriageArrival', title: '到达时间', width: 140}
                , {field: 'carNumber', title: '车牌号', width: 140}
                , {field: 'carriageRemark', title: '状态', width: 140}
                , {fixed: 'right', title: '操作', width: 180, align: 'center', toolbar: '#barDemo'}
            ]]
        });

        table.on('tool(test)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                , layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'edit') {
                layer.confirm('是否确认送达？', function (index) {
                    if(data.carriageArrival!=null){
                        layer.msg("运单已完成");
                    }else {
                    let datas = {
                        id: data.carriageId,
                        carNum: data.carNumber,
                        carSjid: data.carSjid,
                        batchNum: data.batchNum,
                        carriageDestination: data.carriageDestination,
                        carriageStart: data.carriageStart
                    };//传入的参数
                    let url = '/logisticsCarriage/update';
                    $.post(url, datas, function (resp) {
                        if (resp.state == 1) {
                            layer.msg("操作成功");
                            table.reload('testReload');
                        } else {
                            layer.msg("操作失败");
                        }
                    }, "json");
                }
                });
            }
        });

        $(function () {
            $("#souSuo").on("click", function () {
                //执行查询
                var datas = {
                    staffName: $("#staffName").val(),
                    goDate: $("#goDate").val(),
                    outDate: $("#outDate").val(),
                }

                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: datas //需要传到后台的参数
                }, 'data');

            });
        });
    })
</script>
</body>
</html>